<template>
	<view class="bg-white padding-tb padding-lr-xl min-height-100 text-lg">
		<EventBasicDetail :event-id="params.eventId">
			<view slot="custom">
				<view class="margin-top">
					<view class="label">事件评价</view>
					<view class="margin-top-sm">
						<u-radio-group v-model="params.satisfaction" placement="row">
							<u-radio v-for="(item,index) of radios" :key="index" :name="item.value.toString()" :iconSize="30" :size="30" :labelSize="30" :label="item.label" :value="item.value"
								:customStyle="{marginRight: '20rpx'}">
							</u-radio>
						</u-radio-group>
					</view>
					<view class="margin-top-sm width-p-100">
						<u--textarea width="100%" :autoHeight="true" v-model="params.satisfactionRemark" :placeholder="`请填写事件评价`">
						</u--textarea>
					</view>
				</view>
				<view class="btn">
					<view class="logout-btn common-btn login-btn margin-top-lg" @tap="sub">提交</view>
				</view>
			</view>
		</EventBasicDetail>
	</view>
</template>

<script>
	import {
		subRate
	} from "@/api/Interface/event"
	import EventBasicDetail from "../components/EventBasicDetail.vue"
	import {
		RateMap,
		RateDesc,
		RateEnum
	} from "./enums/rate"
	export default {
		components: {
			EventBasicDetail
		},
		data() {
			return {
				message: "数据加载中...",
				params: {
					eventId: null,
					satisfaction: RateEnum[RateMap.good].toString(), // 满意度
					satisfactionRemark: "",
				},
				radios: []
			}
		},
		async onLoad(options) {
			this.params.eventId = options.id;
			this.initRadios();
		},
		methods: {
			initRadios() {
				Object.keys(RateMap).forEach(key => {
					this.radios.push({
						label: RateDesc[key],
						value: RateEnum[key]
					})
				})
			},
			sub() {
				if (uni.$u.test.empty(this.params.eventId)) {
					this.$toast("事件id不可为空")
					return;
				}
				if (uni.$u.test.empty(this.params.satisfaction)) {
					this.$toast("请选择满意度")
					return;
				}
				let me = this;
				console.log('确认提交me.params', JSON.parse(JSON.stringify(me.params)));
				uni.showModal({
					title: "确认提交?",
					async success(modalRes) {
						if (modalRes.confirm) {
							await subRate(me.params).then(res => {
								me.$toast(res.msg)
								if (res.code === 200) {
									setTimeout(() => {
										uni.navigateBack({
											delta: 1
										})
									}, 1500)
								}
							})
						}
					}
				})
			}
		},
	}
</script>

<style lang="less" scoped>
	@import url("@/pages/login/css/login.css");

	.btn {
		width: 100%;
		display: flex;
		justify-content: center;
		margin-top: 60rpx;

		.logout-btn {
			width: 90%;
		}
	}
</style>